import numpy as np
from sklearn.feature_selection import VarianceThreshold

# 示例数据：5 个样本，4 个特征
X = np.array([
    [0, 2, 0, 3],
    [0, 1, 4, 3],
    [0, 1, 1, 3],
    [0, 1, 0, 3],
    [0, 1, 3, 3]
])
print(X.shape)
# 默认 threshold=0 会剔除方差为 0 的特征（第 1 列和第 4 列）
selector = VarianceThreshold(threshold = 0)
X_new = selector.fit_transform(X)

print("降维后形状:", X_new.shape)
print("剩余特征矩阵：\n", X_new)
